<template>
    <div>
        <div class="e-h-400" :id="id"></div>
    </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
    props: {
        id: '',
        data: []
    },
    mounted() {
        var chartDom = document.getElementById(this.id);
        var myChart = echarts.init(chartDom);
        var option;

        //获取数据
        var xAxisdata = []
        var seriesdata1 = []
        var seriesdata2 = []
        if(this.data && this.data.length > 0){
            this.data.forEach((item)=>{
                xAxisdata.push(item.date)
                seriesdata1.push(item.addcount)
                seriesdata2.push(item.completecount)
            })
        }

        option = {
            // title: {
            //   text: 'Stacked Area Chart'
            // },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                data: ['新增', '完成']
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    // data: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
                    data: xAxisdata
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '新增',
                    type: 'line',
                    // stack: 'Total',
                    // areaStyle: {},
                    emphasis: {
                        focus: 'series'
                    },
                    data: seriesdata1
                },
                {
                    name: '完成',
                    type: 'line',
                    // stack: 'Total',
                    // areaStyle: {},
                    emphasis: {
                        focus: 'series'
                    },
                    data: seriesdata2
                }
            ]
        };

        option && myChart.setOption(option);
    }
}
</script>

<style lang="scss" scoped>

</style>